//
//  ViewController.m
//  UI04_作业
//
//  Created by dllo on 16/6/8.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"
#import "AngryButton.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createImageView];
    [self eatButtonAction];
    
    
}
- (void)createImageView{
    self.imageView = [[UIImageView alloc] initWithFrame:self.view.frame];
    self.imageView.image = [UIImage imageNamed:@"angry_00.jpg"];
    self.imageView.userInteractionEnabled = YES;
    
    [self.view addSubview:_imageView];
}
- (void)eatButtonAction{
    //eat 的 button
    AngryButton *button =[AngryButton eatButton:@"eat"];
    button.frame = CGRectMake(20, 400, 60, 60);
    [button addTarget:self action:@selector(didClickedEatButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.imageView addSubview:button];
    //scratch 的button
    AngryButton *scrachButton =[AngryButton eatButton:@"scratch"];
    scrachButton.frame = CGRectMake(20, 500, 60, 60);
    [scrachButton addTarget:self action:@selector(didClickedSearchButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.imageView addSubview:scrachButton];

    AngryButton *cymbalbutton =[AngryButton eatButton:@"cymbal"];
    cymbalbutton.frame = CGRectMake(20, 600, 60, 60);
    [cymbalbutton addTarget:self action:@selector(didClickedCymbalButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.imageView addSubview:cymbalbutton];

    AngryButton *fartbutton =[AngryButton eatButton:@"fart"];
    fartbutton.frame = CGRectMake(320, 400, 60, 60);
    [fartbutton addTarget:self action:@selector(didClickedFartButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.imageView addSubview:fartbutton];
    
    AngryButton *drinkButton =[AngryButton eatButton:@"drink"];
    drinkButton.frame = CGRectMake(320, 500, 60, 60);
    [drinkButton addTarget:self action:@selector(didClickedDrinkButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.imageView addSubview:drinkButton];
    
    AngryButton *pieButton =[AngryButton eatButton:@"pie"];
    pieButton.frame = CGRectMake(320, 610, 60, 60);
    [pieButton addTarget:self action:@selector(didClickedPieButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.imageView addSubview:pieButton];
    
    
    
    AngryButton *stomachButton = [AngryButton eatButton:nil];
    stomachButton.frame = CGRectMake(180, 600, 60, 60);
    [stomachButton addTarget:self action:@selector(didClickedstomachButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.imageView addSubview:stomachButton];
    
}
//eat 的 点击事件
- (void)didClickedEatButton:(UIButton *)button{
    if (self.imageView.isAnimating) {
        return;
    }
    
    NSMutableArray *eatArray = [NSMutableArray array];
    for (NSInteger i = 0 ; i <= 39; i++) {          NSString *path = [[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"eat_%ld",i] ofType:@"jpg"];
            UIImage *name = [UIImage imageWithContentsOfFile:path];
            [eatArray addObject:name];
            
        }
    self.imageView.animationImages = eatArray;
    self.imageView.animationDuration = 2;
    self.imageView.animationRepeatCount = 1;
    [self.imageView startAnimating];
    
   }

//search 的点击事件
- (void)didClickedSearchButton:(UIButton *)button{
        NSMutableArray *eatArray = [NSMutableArray array];
    for (NSInteger i = 0 ; i <= 55; i++) {
        NSString *path = [[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"scratch_%ld",i] ofType:@".jpg"];
        UIImage *name = [UIImage imageWithContentsOfFile:path];
        [eatArray addObject:name];
        
    }
    self.imageView.animationImages = eatArray;
    self.imageView.animationDuration = 3;
    self.imageView.animationRepeatCount = 1;
    [self.imageView startAnimating];
    
}

//cymbal 的点击事件
- (void)didClickedCymbalButton:(UIButton *)button{
    NSMutableArray *cymbalArray = [NSMutableArray array];
    for (NSInteger i = 0 ; i <= 12; i++) {
        NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"cymbal_%ld",i]  ofType:@"jpg"];
        UIImage *name = [UIImage imageWithContentsOfFile:path];
        [cymbalArray addObject:name];
        
    }
    self.imageView.animationImages = cymbalArray;
    self.imageView.animationDuration = 3;
    self.imageView.animationRepeatCount = 1;
    [self.imageView startAnimating];
    
}

//fart 的点击事件
- (void)didClickedFartButton:(UIButton *)button{

    NSMutableArray *eatArray = [NSMutableArray array];
    for (NSInteger i = 0 ; i <= 27; i++) {
        NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"fart_%ld",i]  ofType:@"jpg"];
        UIImage *name = [UIImage imageWithContentsOfFile:path];
        [eatArray addObject:name];
        
    }
    self.imageView.animationImages = eatArray;
    self.imageView.animationDuration = 3;
    self.imageView.animationRepeatCount = 1;
    [self.imageView startAnimating];
    

}

//drink 的点击事件
- (void)didClickedDrinkButton:(UIButton *)button{

    NSMutableArray *drinkArray = [NSMutableArray array];
    for (NSInteger i = 0 ; i <= 80; i++) {
        NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"drink_%ld",i]  ofType:@"jpg"];
        UIImage *name = [UIImage imageWithContentsOfFile:path];
        [drinkArray addObject:name];
        
    }
    self.imageView.animationImages = drinkArray;
    self.imageView.animationDuration = 3;
    self.imageView.animationRepeatCount = 1;
    [self.imageView startAnimating];

}

//pie 的点击事件
- (void)didClickedPieButton:(UIButton *)button{
    NSMutableArray *pieArray = [NSMutableArray array];
    for (NSInteger i = 0 ; i <= 23; i++) {
        NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"pie_%ld",i]  ofType:@"jpg"];
        UIImage *name = [UIImage imageWithContentsOfFile:path];
        [pieArray addObject:name];
        
    }
    self.imageView.animationImages = pieArray;
    self.imageView.animationDuration = 3;
    self.imageView.animationRepeatCount = 1;
    [self.imageView startAnimating];
    
}
//pie 的点击事件
- (void)didClickedstomachButton:(UIButton *)button{

    NSMutableArray *pieArray = [NSMutableArray array];
    for (NSInteger i = 0 ; i <= 33; i++) {
        NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"stomach_%ld",i]  ofType:@"jpg"];
        UIImage *name = [UIImage imageWithContentsOfFile:path];
        [pieArray addObject:name];
        
    }
    self.imageView.animationImages = pieArray;
    self.imageView.animationDuration = 3;
    self.imageView.animationRepeatCount = 1;
    [self.imageView startAnimating];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
